package com.weixin.base.dao.impl;

import java.util.List;
import java.util.Map;

import com.weixin.base.dao.TpDao;
import com.weixin.common.BaseSpringJdbcDao;
import com.weixin.entity.TbWxMenu;
import com.weixin.entity.TbWxUser;

public class TpDaoImpl extends BaseSpringJdbcDao<TbWxMenu, Integer> implements TpDao {
	
	public Class getEntityClass() {
		return TbWxMenu.class;
	}
	
	/**
	 * 查询模版ID
	 */
	public int selectTemplateId(int userId){
		String sql="SELECT top 1 nTemplateId from tbwxuser where nUserId="+userId;
		return getSimpleJdbcTemplate().queryForInt(sql);
	}

	/**
	 * 查询首页菜单
	 * 
	 * @param userId
	 * @param type：类型1幻灯片图片2菜单图片
	 * @return
	 */
	public List<Map<String, Object>> selectTbWxMenu(int userId, int type){
		String sql = "SELECT sContent,sPicUrl,sWxUserUrl FROM tbwxmenu where nUserId="+userId+" and ntype="+type+" and nIsValid=1 order by nOrder ";
		return getSimpleJdbcTemplate().queryForList(sql);
	}
	/**
	 * 返回文章页 srandom 文章随机码
	 */
	public String selectTbWxText(int userId,String srandom){
		String sql="SELECT sContent FROM tbwxtext where nUserId="+userId+" and sRandom='"+srandom+"'";
		return getSimpleJdbcTemplate().queryForObject(sql, String.class);
	}
}
